package 创建型模式.原型;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassNameMain
 * @Description
 * @Author
 * @Date2021/11/18 20:48
 **/
public class Main {
    public static void main(String[] args) throws CloneNotSupportedException {
        // 原型对象
        User sourceUser = new User();
        sourceUser.setName("小周");

        User newUser = sourceUser.clone();
        newUser.getHave().add("车");

        System.out.println("原来对象："+sourceUser);
        System.out.println("复制对象："+ newUser);
        System.out.println(sourceUser.getHave().equals(newUser.getHave()) );

        //创建原型对象
        ConcretePrototype type = new ConcretePrototype();
        type.setAge(18);
        type.setName("C语言中文网");
        List<String> hobbies = new ArrayList<String>();
        hobbies.add("书法");
        hobbies.add("美术");
        type.setHobbies(hobbies);
        //拷贝原型对象
        ConcretePrototype cloneType = type.clone();
        cloneType.getHobbies().add("技术控");
        System.out.println("原型对象：" + type);
        System.out.println("克隆对象：" + cloneType);

    }

}
